using System;
using System.Collections;
using Core.Utils;
using UnityEngine;
using Util;

public class MonoHelper : MonoSingleton<MonoHelper> {
    public Action OnFixedUpdate;
    public Action OnUpdate;


    private void FixedUpdate() {
        OnFixedUpdate?.Invoke();
    }

    private void Update() {
        OnUpdate?.Invoke();
    }
    
    public Coroutine StartCoroutine(Bool condition,Action onExecute) {
        return StartCoroutine(onCoroutineFunc(condition,onExecute));
    }

    public void StopCoroutine(Coroutine coroutine) {
        StopCoroutine(coroutine);
    }
        
    private IEnumerator onCoroutineFunc(Bool condition,Action onExecute) {
        yield return new WaitUntil(() => condition.Value);
        onExecute?.Invoke();
    }
}
